﻿Public Class consultaLSorteo
    Private mModoAcceso As String
    Public Property ModoAcceso() As String
        Get
            Return mModoAcceso
        End Get
        Set(ByVal value As String)
            mModoAcceso = value.Trim.ToUpper
        End Set
    End Property

    Private Sub consultaLSorteo_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Deactivate
        Salir()
    End Sub
    Private Sub consultaLSorteo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnModificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModificar.Click
        Seleccionar()
    End Sub

    Private Sub btnVolver_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVolver.Click
        Salir()
    End Sub
    Public Sub FormatoGrilla()
        lvSorteo.Items.Clear()
        lvSorteo.Columns.Clear()
        lvSorteo.Columns.Add("Cod. Sorteo", 80) '0
        lvSorteo.Columns.Add("Fecha", 90) '1
        lvSorteo.Columns.Add("Cliente", 250) '2(Cod & Nombre)
        lvSorteo.Columns.Add("Producto", 250) '3 (Cod & Nombre)
        lvSorteo.Columns.Add("Estado", 80) '4

    End Sub
    Public Sub CargaGrilla(ByVal ListaSorteo As List(Of clsSorteo))
        FormatoGrilla()
        Dim Sorteo As New clsSorteo()
        Dim CLiente As New clsCliente()
        Dim Producto As New clsCatalogo()
        Dim i As Int32

        Try
            For i = 0 To (ListaSorteo.Count - 1)
                Sorteo = ListaSorteo.Item(i)
                CLiente = Sorteo.Cliente
                Producto = Sorteo.Producto
                lvSorteo.Items.Add(Sorteo.Sort_Id.ToString.Trim)
                lvSorteo.Items(i).SubItems.Add(Sorteo.Fecha.ToString.Trim)
                lvSorteo.Items(i).SubItems.Add(CLiente.Cli_Id.ToString.Trim & " - " & CLiente.Apellido.Trim.ToUpper & " " & CLiente.Nombre.Trim.ToUpper)
                lvSorteo.Items(i).SubItems.Add(Producto.Prod_Id.ToString.Trim & " - " & Producto.Descripcion.Trim & " " & Producto.Marca.Trim & " " & Producto.Modelo.Trim)
                Select Case Sorteo.Estado
                    Case "P"
                        lvSorteo.Items(i).SubItems.Add("PENDIENTE")
                    Case "C"
                        lvSorteo.Items(i).SubItems.Add("CONTACTADO")
                    Case "V"
                        lvSorteo.Items(i).SubItems.Add("VENCIDO")
                    Case "E"
                        lvSorteo.Items(i).SubItems.Add("ENTREGADO")
                End Select
            Next
        Catch ex As Exception
        Finally
            Sorteo.Dispose()
            CLiente.Dispose()
            Producto.Dispose()
        End Try
    End Sub
    Private Sub Seleccionar()
        Dim Sorteo As New clsSorteo()
        Dim SorteoDao As New daoSorteo()

        If lvSorteo.SelectedItems.Count = 1 Then
            Sorteo = SorteoDao.TraeSorteo(Convert.ToInt32(lvSorteo.SelectedItems(0).Text.Trim))
        Else
            MessageBox.Show("Seleccione un Sorteo para continuar", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If

        Select Case ModoAcceso
            Case "MODI SORT"
                modificarSorteo.AsignaCampos(Sorteo)
                modificarSorteo.Enabled = True
        End Select
        Me.Close()
    End Sub
    Private Sub Salir()
        Select Case ModoAcceso
            Case "MODI SORT"
                modificarSorteo.Enabled = True
        End Select
        Me.Close()
    End Sub

    Private Sub lvSorteo_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvSorteo.DoubleClick
        Seleccionar()
    End Sub

End Class